package com.newsmanagement.dao;

import com.newsmanagement.entity.NewsCategoryEntity;
import com.newsmanagement.entity.ReturnedMessages;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author xbr
 * 2017/12/5
 * 用户和新闻分类信息表信息
 */
@Mapper
public interface IEumCategoryServiceDao {

    /**
     * 根据用户和新闻分类id修改喜欢或者不喜欢的数据
     * @param eumId 用户id
     * @param categoryId 分类id
     * @param likeCategory 是否喜欢：1，喜欢；0，不喜欢;-1,不喜欢不讨厌
     * @return 修改 插入的数据条数
     */
    @Update("UPDATE EUM_NEWSCATEGORY_T SET LIKE_CATEGORY = #{arg2} WHERE CATEGORY_ID = #{arg1} AND EUM_ID = #{arg0}")
    int updateEumCategoryLike(Integer eumId ,Integer categoryId ,Integer likeCategory);


    /**
     * 创建用户和新闻分类信息表信息
     * @param eumId 用户id
     * @param categoryId 分类id
     * @param likeCategory 是否喜欢：1，喜欢；0，不喜欢;-1,不喜欢不讨厌
     * @return int 插入的数据条数
     */
    @Insert("INSERT INTO EUM_NEWSCATEGORY_T (EUM_ID, CATEGORY_ID ,LIKE_CATEGORY) VALUES (#{arg0} ,#{arg1} ,#{arg2})")
    int addEumCategory(Integer eumId ,Integer categoryId ,Integer likeCategory);

    /**
     * 根据用户主键修改对应的用户信息
     * @param categoryId 新闻分类id
     * @param categoryName 新闻分类名称
     * @return int 修改的数据条数
     */
    @Update("update NEWS_CATEGORY_T set CATEGORY_NAME = #{arg1} where CATEGORY_ID = #{arg0}")
    int updateNewscategoryNameByCategoryId(Integer categoryId, String categoryName);


    /**
     * （前台）查询新闻分类（过滤个人不感兴趣分类）
     * @param eumId 用户主键
     * @param like 是否喜欢：1，喜欢；0，不喜欢;-1,不喜欢不讨厌
     * @return List<Map<String ,Object>>
     */
    @Select("SELECT " +
                "DISTINCT(category.CATEGORY_ID) categoryId ," +
                "category.CATEGORY_NAME categoryName ," +
                "category.ORDER_NUMBER orderNumber " +
            "FROM NEWS_CATEGORY_T category " +
            "LEFT JOIN EUM_NEWSCATEGORY_T eumCategory ON category.CATEGORY_ID = eumCategory.CATEGORY_ID " +
            "WHERE category.DELETE_FLAG = 1 " +
            "AND eumCategory.LIKE_CATEGORY != #{arg1} " +
            "AND eumCategory.DELETE_FLAG = 1 " +
            "AND eumCategory.EUM_ID = #{arg0}  " +
            "ORDER BY ORDER_NUMBER DESC")
    List<Map<String ,Object>> likeCategoryList(Integer eumId , Integer like);
}
